// import 'package:ls_work/a_yyt/models/care_report_entity.dart';
import 'package:ls_work/a_yyt/models/gean_entity.dart';
import 'package:ls_work/mvp/base_page_presenter.dart';
import 'package:ls_work/net/HttpUtil.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/a_yyt/page/home_gean_page.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/widgets/state_layout.dart';
import 'dart:convert';
import 'package:dio/dio.dart';

class GeAnPresenter extends BasePagePresenter<HomeGeAnPageState> {
  Future fectData(
      String text, int page, bool isShowDialog, String elderNameLike) async {
    view.showProgress();
    Map<String, dynamic> map = {
      'page': page,
      'rows': 20,
      'type': 0,
      'wrapper': true
    };
    if (elderNameLike != null && elderNameLike.isNotEmpty) {
      map['elderNameLike'] = elderNameLike;
    }
    HttpUtil.instance
        .getDio()
        .post(HttpApi.caseList, data: map,options: PostRequest.urlencodedHeader)
        .then((r) {
      ///
      view.closeProgress();
      if (r.statusCode == 200) {
        Map<String, dynamic> map = json.decode(r.toString());

        if (map["code"].toString() == "0") {
          if (map['data'] != null) {
            GeAnEntity model = GeAnEntity.fromJson(map['data']);
            if ((model.rows??[]).length > 0) {
              view.provider.setHasMore((model.rows??[]).length == 20);
              if (page == 1) {
                /// 刷新
                view.provider.list.clear();
                view.provider.addAll(model.rows??[]);
              } else {
                view.provider.addAll(model.rows??[]);
              }
            } else {
              view.provider.setStateType(StateType.empty);
            }
          } else {
            view.showToast(map["msg"]);
          }
        }
      } else {
        view.showToast(r.statusCode.toString());
        view.provider.setHasMore(false);
        view.provider.setStateType(StateType.empty);
      }
    }).catchError((e) {
      view.closeProgress();
      print(e.toString());
      view.provider.setHasMore(false);
      view.provider.setStateType(StateType.empty);
      view.showToast(getErrorMessage((e as DioError).type));
    });
  }
}
